package com.net.wheels.mybatis.generator;


import com.net.wheels.mybatis.generator.base.MapperGenerator;
import com.net.xpay.common.domain.backup.X1;

/**
 * 分库domain模块代码生成
 */
public class GeneratorShardMain {

    public static void main(String[] args) {
        Class clazz = X1.class;//需要生成的类  根据实际情况修改

        genCode(clazz);
    }

    public static void genCode(Class clazz) {
        String projectPath = System.getProperty("user.dir");
        String sqlPath = projectPath + "/updates/shard";
        String domainPath = getSourcePath(clazz);//domain所在路径
        if (!domainPath.endsWith("domain")) {
            sqlPath = sqlPath + domainPath.substring(domainPath.indexOf("domain") + 6);
        }
        String shardName = "";//分库名目前为hermes,不分库写""

        new MapperGenerator(clazz, domainPath, sqlPath, false, shardName).start();
    }

    //获取class所在文件路径
    private static String getSourcePath(Class clazz) {
        String path = clazz.getResource("").toString().replace("target/classes", "src/main/java")
                .replace("file:", "");
        return path.substring(0, path.lastIndexOf('/'));
    }


}
